Questions
3 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
03 / 45

What is the syntax of a pseudo-element?

Syntax of Pseudo-Elements in CSS

A pseudo-element in CSS is used to style a specific part of an element or insert content before or after it. The standard syntax uses double colons :: followed by the pseudo-element name.

Key Points
  1. 1

    Syntax format: selector::pseudo-element { properties }

  2. 2

    Common pseudo-elements include ::before, ::after, ::first-letter, and ::first-line.

  3. 3

    Single colon : notation (e.g., :before) is also supported for backward compatibility with older browsers.

  4. 4

    Pseudo-elements do not exist in the DOM; they are virtual elements used for styling purposes.

Example: Using ::before and ::first-letter

In this example, ::first-letter targets and styles the first letter of the paragraph, while ::before inserts a star before the paragraph text.

Best Practices
  1. 1

    Use pseudo-elements to style or decorate content without modifying the HTML structure.

  2. 2

    Combine with CSS properties like content, color, font-size, and background.

  3. 3

    Prefer double colon :: notation for clarity and modern standards.

  4. 4

    Test pseudo-elements across browsers to ensure consistent rendering.

Difficulty: 3/10
Topics: pseudo-element syntax, CSS selector specificity, before/after usage

Scenario Questions

0-2 years experience
  1. 1

    How would you add a small star icon after every .review-rating element using CSS pseudo-elements?

  2. 2

    What happens if you write :before instead of ::before in modern CSS — will it still work?

  3. 3

    You’re trying to style a ::after element on a button, but nothing shows up. What’s the first thing you check?

2-5 years experience
  1. 1

    A designer wants a speech bubble tooltip using ::before and ::after, but the triangle part is misaligned on mobile — how do you debug and fix it?

  2. 2

    We’re using ::before to add decorative icons in a list, but now the screen reader is announcing them. How do you fix accessibility without removing the visual effect?

  3. 3

    Our CSS file has a ::before rule that’s being overridden by another rule — how do you trace the specificity conflict without breaking other styles?

5-8 years experience
  1. 1

    You’re building a reusable card component that uses ::before for a border accent, but it breaks when the card is used inside a scrollable container with overflow hidden — how do you redesign this without losing the visual effect?

  2. 2

    In a high-traffic component library, we’re using pseudo-elements for icons to avoid extra DOM nodes. What performance or rendering tradeoffs should you consider at scale?

  3. 3

    A legacy UI uses ::after to inject text labels dynamically — now we’re migrating to a React component system. How do you decide whether to keep the pseudo-element or move it to JSX?

8+ years experience
  1. 1

    We’re standardizing a design system across 12 teams, and some are using pseudo-elements for critical UI cues while others use real elements — how do you enforce consistency without breaking accessibility or performance?

  2. 2

    A legacy product relies heavily on ::before and ::after for layout and spacing. We want to migrate to CSS Grid, but removing these breaks dozens of pages. What’s your migration strategy?

  3. 3

    How would you architect a CSS architecture that minimizes reliance on pseudo-elements for semantic content while still allowing designers to use them for decoration — and how do you communicate that boundary across engineering and design teams?

Follow-up Questions

  • What happens if you forget the content property?
  • How would you debug a ::before element that’s not showing up?
  • Can you use pseudo-elements on self-closing tags like <img>?